package com.humanmonth.home.component.page.htree.remote
{
	import com.humanmonth.home.component.page.htree.MyLine;
	import com.humanmonth.home.component.page.htree.NodeAs;
	import com.humanmonth.util.text.XMLUtil;
	
	public class TreeToXml
	{
		/**
		 * 构建xml 
		 */
		public function buildXml():String{
			return XMLUtil.xmlHeader+XMLUtil.buildXml("result",this.buildLinesXml()+this.buildNodesXml())
		}
		
		/**
		 * 构建节点xml 
		 */
		private function buildNodesXml():String{
			var results:String="";
			for each(var node:NodeAs in NodeAs.allNode){
				var result:String="";
				result+=XMLUtil.buildXml("id",node.myId);
				result+=XMLUtil.buildXml("name",node.myName);
				result+=XMLUtil.buildXml("order",node.myOrder);
				result+=XMLUtil.buildXml("x",node.x);
				result+=XMLUtil.buildXml("y",node.y);
				results+=XMLUtil.buildXml("node",result);
			}
			return XMLUtil.buildXml("nodes",results);
		}
		
		/**
		 * 构建线条xml
		 */
		private function buildLinesXml():String{
			var results:String="";
			for each(var line:MyLine in MyLine.allLines){
				var result:String="";
				result+=XMLUtil.buildXml("start",line.startNode.myId);
				result+=XMLUtil.buildXml("end",line.endNode.myId);
				results+=XMLUtil.buildXml("line",result);
			}
			return XMLUtil.buildXml("lines",results);
		}
	}
}